/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package fr.loof.fonzie;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.LockModeType;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;

/**
 * @author <a href="nicolas@apache.org">Nicolas De Loof</a>
 */
@NamedQuery( name = "User.sampleNamedQuery", query = "select e from User e where firstName = :firstName and lastName = :lastName" )
@Entity
public class User
    extends People
{
    public User()
    {
    }

    public User( String firstName, String lastName )
    {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    @Id
    @GeneratedValue
    public long id;

    public Date birthDate;

    public String twitter;

    public String initials;

    @ManyToOne
    public Address address;

    public native static People find( long id );

    public native static People getReference( long id );

    public native static Collection<User> findAll();

    public native static User findWhereSampleNamedQuery( String firstName, String lastName );

    public native static User findByFirstName( String firstName );

    public native static Collection<User> findByLastName( String firstName );

    public native static Collection<User> findByLastNameIn( Collection<String> firstName );

    public native static Collection<User> findByLastNameNotIn( Collection<String> firstName );

    public native static Collection<User> findByLastName( String firstName, int max );

    public native static Collection<User> findByLastName( String firstName, int max, int from );

    public native static Collection<User> findByFirstNameOrderByLastName( String firstName );

    public native static Collection<User> findByFirstNameOrderByLastNameDesc( String firstName );

    public native static Collection<User> findByFirstNameOrderByFirstNameAndLastNameDesc( String firstName );

    public native static List<User> findByFirstNameEquals( String firstName );

    public native static List<User> findByFirstNameNotEquals( String firstName );

    public native static Collection<User> findByFirstNameLike( String firstName );

    public native static Collection<User> findByBirthDateGreaterEquals( Date now );

    public native static Collection<User> findByBirthDateGreaterThan( Date now );

    public native static Collection<User> findByBirthDateLessEquals( Date now );

    public native static Collection<User> findByBirthDateLessThan( Date now );

    public native static Collection<User> findByBirthDateBetween( Date from, Date to );

    public native static User findByFirstNameAndLastName( String firstName, String lastName );

    public native static Collection<User> findByFirstNameNull();

    public native static Collection<User> findByFirstNameNotNull();

    public native static Collection<User> findWithCriterias( Criteria... criterias );

    public native static User findByFirstNameJoinAddressAndLastName( String firstName, String lastName );

    public native static User findByFirstNameJoinFetchAddressAndLastName( String firstName, String lastName );

    // Expected to fail
    public native static User findByTwitter( Date now );

    // Expected to NOT collide with the "in" keyword
    public native static User findByInitials( String initials );

    public native static long count();

    public native static long countByFirstNameNotNull();

    public static native long countByFirstNameGroupByLastName( String fistName );

    public native void persist();

    public native void remove();

    public native void refresh();

    public native User merge();

    public native boolean isManaged();

    public native void lock( LockModeType mode );

    public Address getAddress()
    {
        return address;
    }

    public void setAddress( Address address )
    {
        this.address = address;
    }

    /**
     * {@inheritDoc}
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        return firstName + " " + lastName;
    }

}
